//useSelector 这是一个自定义的hook ，方便 react组件与react-redux 进行通信
/**
 * useSelector 从 store state 中读取一个值，并且可以订阅和更新，
 * 而 useDispatch 返回 store 的 dispatch 方法让你可以去 dispatch actions。
 */

// reducers.js

const DefaultState = {
   count: 0,
   msgInfo: [],
}

export const INCREMENT = 'INCREMENT'
export const DECREMENT = 'DECREMENT'
export const UPDADEMSG = 'UPDADEMSG'

export const reducer = (state = DefaultState, action) => {
   switch (action.type) {
      case INCREMENT:
         return { ...state, count: state.count + 1 }
      case DECREMENT:
         return { ...state, count: state.count - 1 }
      case UPDADEMSG:
         return { ...state, msgInfo: ((state.msgInfo).concat(action.payload)) }
      default:
         return state
   }
}

export const getDispatchObject = (type, payload) => {
   return { type, payload }
}
